<?php

/**
 * Description of emailTemplateSaveAction
\* www.teuker.nl - mail@teuker.nl
 * 
 * @author francisc
 */

class emailTemplateSaveAction extends sfAction {

    public function execute($request) {
        $category = $request->getParameter('category');
        $body = $request->getParameter('body');
        $subject = $request->getParameter('subject');

        $template_types = SqlEngine::getTemplateTypes(array('name' => 'email'));
        $template_category = SqlEngine::getTemplateCategory(array('name' => $category));
        
        $template = SqlEngine::getTemplates(array('category_id' => $template_category[0]['template_category_id'],
                                                  'type_id' => $template_types[0]['template_type_id']));
                
        SqlEngineCore::get()->update(array(
                        'table' => 'template',
                        'columns' => array(
                            'restaurant_id' => array('value' => $this->getUser()->getAttribute('current_restaurant_id'), 'type' => PDO::PARAM_INT),
                            'subject' => $subject,
                            'body' => $body),
                        'where' => array('template_id' => $template[0]['template_id'])));

        Util::loadI18NHelper();
        return $this->renderText(__('Template saved'));
    }
}
